import 'package:fish_redux/fish_redux.dart';

import 'action.dart';
import 'state.dart';

Reducer<VillageAccessRobbitState> buildReducer() {
  return asReducer(
    <Object, Reducer<VillageAccessRobbitState>>{
      VillageAccessRobbitAction.action: _onAction,
      VillageAccessRobbitAction.refresh: _refresh,
      VillageAccessRobbitAction.openSettingPage: _openSettingPage,
    },
  );
}

VillageAccessRobbitState _onAction(
    VillageAccessRobbitState state, Action action) {
  final VillageAccessRobbitState newState = state.clone();

  return newState;
}

VillageAccessRobbitState _refresh(
    VillageAccessRobbitState state, Action action) {
  VillageAccessRobbitState newState = state.clone();

  return newState;
}

VillageAccessRobbitState _openSettingPage(
    VillageAccessRobbitState state, Action action) {
  VillageAccessRobbitState newState = state.clone();
  if (newState.editingDeviceId > 0 && newState.editingDeviceId == action.payload) {
    newState.editingDeviceId = -1;
  } else {
    newState.editingDeviceId = action.payload;
  }
  return newState;
}
